/**
 * 订单管理 交易订单
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>交易订单</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">
      <el-form-item>
        <el-input size="small" v-model="formInline.orderNo" placeholder="输入订单号"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
      </el-form-item>
    </el-form>
    <!--列表-->
    <el-table size="small" :data="listData" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column type="expand">
      <template slot-scope="props">
        <el-table size="small" :data="props.row.proList"   style="width: 100%;">
          <el-table-column sortable prop="photo" label="产品照片"  width="130">
              <!-- 图片的显示 -->
              <template slot-scope="scope">            
                <img :src="scope.row.photo"  width="100" height="50" />
              </template>
          </el-table-column>
          <el-table-column sortable prop="proName" label="产品名称" width="200">
          </el-table-column>
          <el-table-column sortable prop="descri" label="描述" width="300">
          </el-table-column>
          <el-table-column sortable prop="amount" label="单价" width="300">
          </el-table-column>
          <el-table-column sortable prop="num" label="数量" width="100">
          </el-table-column>
        </el-table>
      </template>
    </el-table-column>
      <el-table-column align="center" type="index" width="60">
      </el-table-column>
      <el-table-column sortable prop="orderNo" label="订单号" width="150" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="totalAmount" label="总金额（元）" width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="discountAmount" label="折扣金额（元）" width="140" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="actualAmount" label="实际支付（元）" width="140" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="orderStatus" label="订单状态" width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="datatime" label="创建时间" width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <div>{{scope.row.datatime|timestampToTime}}</div>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作" min-width="150">
        <template slot-scope="scope">
          <el-button size="mini" type="info" @click="showReceive(scope.$index, scope.row)">客户地址</el-button>
          <!--<el-button size="mini" type="info" @click="showDiscount(scope.$index, scope.row)">优惠券</el-button>-->
          <el-button size="mini" type="success" :disabled='scope.row.orderStatus_ori != 0' @click="recOrder(scope.$index, scope.row)">接单</el-button>
          <el-button size="mini" type="danger" :disabled='scope.row.orderStatus_ori != 0' @click="refOrder(scope.$index, scope.row)">拒绝</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>
    <!-- 展示客户地址 -->
    <el-dialog :title="title" :visible.sync="editFormVisible" width="50%" @click="closeDialog">
     <el-form label-width="100px" :model="editForm"  ref="editForm">
        <el-form-item label="联系人" prop="linkman">
          <el-input size="small" disabled v-model="editForm.linkman" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="联系电话" prop="phoneNum">
          <el-input size="small" disabled v-model="editForm.phoneNum" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="地址" prop="detailAddress">
          <el-input size="small" disabled v-model="editForm.detailAddress" auto-complete="off"></el-input>
        </el-form-item>
      </el-form>
    </el-dialog>
     <!-- 展示优惠券 -->
    <el-dialog :title="title1" :visible.sync="editFormVisible1" width="70%" @click="closeDialog1">
       <el-table size="small" :data="editForm"   style="width: 100%;">
          <el-table-column sortable prop="satisfyAmount" label="满足金额" width="200">
          </el-table-column>
          <el-table-column sortable prop="discountAmount" label="折扣金额" width="300">
          </el-table-column>
          <el-table-column sortable prop="descri" label="描述" width="300">
          </el-table-column>
          <el-table-column sortable prop="type" label="优惠券类型" width="100">
          </el-table-column>
        </el-table>
    </el-dialog>
  </div>
</template>

<script>
import { orderList, orderRec } from '../../api/payMG'
import Pagination from '../../components/Pagination'
export default {
  data() {
    return {
      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      editFormVisible1: false,
      title: '客户地址',
      title1: '使用优惠券信息',
      editForm: {
        no: '',
        orderNo: '',
        datatime: '',
        actualAmount: '',
        discountAmount: '',
        orderStatus: '',
      },
      formInline: {
        pageIndex: 1,
        pageSize: 10,
        orderNo:null,
      },
      userparm: [], //搜索权限
      listData: [], //用户数据
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10
      }
    }
  },
  // 注册组件
  components: {
    Pagination
  },
  /**
   * 数据发生改变
   */

  /**
   * 创建完毕
   */
  created() {
    this.getdata(this.formInline)
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    // 获取公司列表
    getdata(parameter) {
      this.loading = true

      /***
       * 调用接口，注释上面模拟数据 取消下面注释
       */

     orderList(parameter)
        .then(res => {
          this.loading = false
          if (res.code == '0') {
            this.$message({
              type: 'info',
              message: res.msg
            })
          } else {
            for(let i = 0;i<res.data.datas.length;i++){
              let d = res.data.datas[i].proList;
              for(let j = 0;j<d.length;j++){
                d[j].photo = 'data:image/png;base64,'+d[j].photo
              }
            }
            this.listData = res.data.datas
           
            // 分页赋值
            this.pageparm.currentPage = this.formInline.pageIndex
            this.pageparm.pageSize = this.formInline.pageSize
            this.pageparm.total = res.data.total
          }
        })
        .catch(err => {
          this.loading = false
          this.$message.error('产品类型加载失败，请稍后再试！')
        })
    },
    // 分页插件事件
    callFather(parm) {
      this.formInline.pageIndex = parm.currentPage
      this.formInline.pageSize = parm.pageSize
      this.getdata(this.formInline)
    },
    // 搜索事件
    search() {
      this.getdata(this.formInline)
    },
    //展示客户信息
    showReceive: function(index, row) {
      this.editFormVisible = true
      this.editForm = row.receiveInfo
    },
    //展示优惠券
    showDiscount: function(index, row) {
      this.editFormVisible1 = true
      this.editForm = row.disList
    },
    // 编辑、增加页面保存方法
    submitForm(editData) {
      this.$refs[editData].validate(valid => {
        if (valid) {
          ConfigSave(this.editForm)
            .then(res => {
              this.editFormVisible = false
              this.loading = false
              if (res.success) {
                this.getdata(this.formInline)
                this.$message({
                  type: 'success',
                  message: '公司保存成功！'
                })
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
            .catch(err => {
              this.editFormVisible = false
              this.loading = false
              this.$message.error('支付配置信息保存失败，请稍后再试！')
            })
        } else {
          return false
        }
      })
    },
    // 接单
    recOrder(index, row) {
      let param = {
        no:row.no,
        orderStatus:1
      }
      orderRec(param)
        .then(res => {
          if (res.code == '1') {
            this.$message({
              type: 'success',
              message: '接单成功!'
            })
            this.getdata(this.formInline)
          } else {
            this.$message({
              type: 'info',
              message: res.msg
            })
          }
        })
        .catch(err => {
          this.loading = false
          this.$message.error('接单失败，请稍后再试！')
        })
      
    },
    // 拒绝
    refOrder(index, row) {
      let param = {
        no:row.no,
        orderStatus:6
      }
      orderRec(param)
        .then(res => {
          if (res.code == '1') {
            this.$message({
              type: 'success',
              message: '拒绝成功!'
            })
            this.getdata(this.formInline)
          } else {
            this.$message({
              type: 'info',
              message: res.msg
            })
          }
        })
        .catch(err => {
          this.loading = false
          this.$message.error('拒绝失败，请稍后再试！')
        })
      
    },
    // 关闭编辑、增加弹出框
    closeDialog(formName) {
      this.editFormVisible = false
      this.$refs[formName].resetFields()
    },
    // 关闭编辑、增加弹出框
    closeDialog1(formName) {
      this.editFormVisible1 = false
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
</style>

 
 

 